package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.wemedia.service.WmStatisticsService;
import com.heima.wemedia.vos.WmNewsStatisticsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/statistics/")
@Slf4j
public class WmStatisticsController {

    @Autowired
    private WmStatisticsService wmStatisticsService;

    /**
     * 图文数据统计 上方4个数据的相关统计
     *
     * @param dimensionDto 前端传递的条件dto
     * @return 返回结果
     */
    @GetMapping("newsDimension")
    public ResponseResult<Map<String, Integer>> newsDimension(String beginDate, String endDate) {
        log.info("图文数据统计功能:beginDate:{},endDate:{}", beginDate, endDate);
        Map<String, Integer> data = wmStatisticsService.newsDimension(beginDate, endDate);
        return ResponseResult.okResult(data);
    }

    /**
     * 图文数据统计 下方数据分页查询
     *
     * @return 返回结果
     */
    @GetMapping("newsPage")
    public PageResponseResult newPage(String beginDate, String endDate, Integer page, Integer size) {
        log.info("图文数据统计分页查询功能:beginDate:{},endDate:{},page:{},size:{}", beginDate, endDate, page, size);
        Page<WmNewsStatisticsVo> newPage= wmStatisticsService.newPage(beginDate, endDate, page, size);
        return PageResponseResult.getPageResponseResult(newPage);
    }
}
